import axios from 'axios'
// 设置基准路径
axios.defaults.baseURL = 'http://127.0.0.1:3000/'

// 允许axios传递cookie数据，因为默认情况下，axios并不会传递cookie
axios.defaults.withCredentials = true

// 登录
export const login = (pa) => {
  return axios.post('/employee/employeeLogin', pa)
    .then(res => {
      return res.data
    })
}

// 退出登录
export const logout = () => {
  return axios.get('/employee/employeeLogout')
    .then(res => {
      return res.data
    })
}

// 用户信息查询
export const getUserList = (pa) => {
  return axios.get('/user/queryUser', { params: pa })
    .then(res => {
      return res.data
    })
}

// 用户禁用启用
export const updateUser = (pa) => {
  return axios.post('/user/updateUser', pa)
    .then(res => {
      return res.data
    })
}

// 判断用户是否登录
export const checkRootLogin = () => {
  return axios.get('/employee/checkRootLogin')
    .then(res => {
      return res.data
    })
}
// 查询一级分类管理数据
export const queryCategoryFirst = (pa) => {
  return axios.get('/category/queryTopCategoryPaging', {params: pa})
    .then(res => {
      return res.data
    })
}

// 添加一级分类数据
export const addCategoryFirst = (categoryName) => {
  return axios.post('/category/addTopCategory', {categoryName: categoryName})
    .then(res => {
      return res.data
    })
}

// 修改一级分类数据
export const editCategoryFirst = (pa) => {
  return axios.post('/category/updateTopCategory', pa)
    .then(res => {
      return res.data
    })
}

// 查询二级分类管理数据
export const queryCategorySecond = (pa) => {
  return axios.get('/category/querySecondCategoryPaging', {params: pa})
    .then(res => {
      return res.data
    })
}

// 添加二级分类数据
export const addCategorySecond = (pa) => {
  return axios.post('/category/addSecondCategory', pa)
    .then(res => {
      return res.data
    })
}

// 修改二级分类数据
export const editCategorySecond = (pa) => {
  return axios.post('/category/updateSecondCategory', pa)
    .then(res => {
      return res.data
    })
}

// 查询商品管理数据
export const queryProductDetailList = (pa) => {
  return axios.get('/product/queryProductDetailList', {params: pa})
    .then(res => {
      return res.data
    })
}

// 添加商品信息
export const addProduct = (pa) => {
  return axios.post('/product/addProduct', pa)
    .then(res => {
      return res.data
    })
}

// 编辑商品信息
export const updateProduct = (pa) => {
  return axios.post('/product/updateProduct', pa)
    .then(res => {
      return res.data
    })
}
